package com.global.test.chain.security.authentication;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.global.domain.Authority;
import com.global.domain.Role;
import com.global.domain.User;
import com.global.emc.core.CoreUser;
import com.global.emc.security.authentication.AuthorityHandler;
import com.global.test.service.user.AuthorityService;

/**   
 *  
 * @Description:  [用一句话描述该文件做什么]   
 * @Author:       [Joly_Huang]   
 * @CreateDate:   [2014年3月20日 下午12:11:34]   
 * @UpdateUser:   [Joly_Huang]   
 * @UpdateDate:   [2014年3月20日 下午12:11:34]   
 * @UpdateRemark: [说明本次修改内容]  
 * @Version:      [v1.0] 
 *    
 */
@Component
public class AuthorityHandlerImpl implements AuthorityHandler {

	private AuthorityService authorityService;
	
	public AuthorityService getAuthorityService() {
		return authorityService;
	}
	@Resource
	public void setAuthorityService(AuthorityService authorityService) {
		this.authorityService = authorityService;
	}


	@Override
	public void handlerAuthorities(CoreUser coreUser) {
		User user = User.convertCoreUser(coreUser);
		for(Role role : user.getRoles()){
			List<Authority> authorities = authorityService.getAuthorities(role.getId());
			role.setAuthorities(authorities);
		}
	}

}
